package zw_901_1000.zw_922_按奇偶排序数组II;

class Solution {

    public static void main(String[] args) {
        int[] nums = {4,2,5,7};
        int[] array = sortArrayByParityII(nums);
        for (int i : array) {
            System.out.print(i + " ");
        }
    }

    public static int[] sortArrayByParityII(int[] nums) {
        int n = nums.length;
        int j = 1;
        for (int i = 0; i < n; i += 2) {
            if (nums[i] % 2 == 1) {
                while (nums[j] % 2 == 1) {
                    j += 2;
                }
                swap(nums, i, j);
            }
        }
        return nums;
    }
    public static void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
